package io.jboot.fly.utils;

import io.jboot.fly.model.Post;


/**
 * Created by admin on 2018/9/13.
 */
public class EsThreadUtils implements  Runnable{
    public static String CREATE_POST_INDEX="create";
    public static String UPDATE_POST_INDEX="update";
    public static String DELETE_POST_INDEX="delete";
    private String action;
    private Post post;

    public EsThreadUtils(String action, Post post) {
        this.action = action;
        this.post = post;
    }

    @Override
    public void run() {
        try {
            if(CREATE_POST_INDEX.equals(action)){
                ElaticSearchUtils.createPostIndex(this.post);
            }else if(UPDATE_POST_INDEX.equals(this.post)){
                ElaticSearchUtils.updatePost(post);
            }else if(DELETE_POST_INDEX.equals(this.post)){
                ElaticSearchUtils.deletePost(post);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
